/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alcatelparser.tags;

import alcatelparser.modules.AlgoUtil;
import alcatelparser.modules.BuilderFactory;
import alcatelparser.modules.Env;
import alcatelparser.modules.I;

/**
 *
 * @author geniuz
 */
public class ParticipantInfoTag extends DefaultParserTag
{

    public ParticipantInfoTag()
    {
        value = "";
    }
    private String value;
    public String GetResult(){
        if (value.length()>2)
            return value;//.substring(0,value.length()-2);
        else {
            return value;
        }
    }
    public final void parseTag(int ai[], int i)
    {
        value = "";
        setStandartLength(ai, i);
        _array = ai;
        _startParsePosition = i;
        int j = AlgoUtil.getLength(ai, i + 1);
        int k = 2;
        if(Env.getEnv().isFullForm())
            BuilderFactory.getBuilder().writeTagContent(3, 0, getTagPropertiesValue(I.I(6976)), getTagIdentifyContent(i, i + 1));
        PhoneNumberDecoratorTag phonenumberdecoratortag = new PhoneNumberDecoratorTag();
        int x = 0;
        while(j > 0) 
        {
            int l = i + k;
            int i1 = calculateInnerTagType(_array[l]);
            int j1 = AlgoUtil.getLength(_array, l + 1);
            int k1 = j1 + 2;
            if(isTagChecked(i1))
                if(Env.getEnv().isFullForm())
                {
                    String s = getTagPropertiesValue((new StringBuilder()).append(I.I(6997)).append(i1).toString());
                    String p1 = getHexStringContent(l + 2, j1);
                    String s2 = (new StringBuilder()).append(getTagIdentifyContent(l, l + 1)).append(p1).toString();
                    BuilderFactory.getBuilder().writeTagContent(4, 0, s, s2);
                    phonenumberdecoratortag.decorateTag(ai, l, true, j1);
                    String phonenumber = phonenumberdecoratortag.GetPhoneNumber();
                    //if (s.equals("callingPartyNumber") || s.equals("calledPartyNumber"))
                    x++;
                    value += phonenumber + "~";
                    
                } else
                {
                    String s1 = getReducedTagPropertiesValue((new StringBuilder()).append(I.I(6997)).append(i1).toString());
                    if(Env.getEnv().isFieldsDecoding())
                    {
                        phonenumberdecoratortag.setReducedTagName(s1);
                        phonenumberdecoratortag.decorateTag(ai, l, true, j1);
                    } else
                    {
                        BuilderFactory.getBuilder().writeTagContent(1, 0, s1, getHexStringContent(l + 2, j1));
                    }
                }
            j -= k1;
            k += k1;
        }
        for(int sss=x;sss<4;sss++){
            value += "~";
        }
    }

    private boolean isTagChecked(int i)
    {
        switch(i)
        {
        case 0: // '\0'
            return isTagChecked(I.I(1499));

        case 1: // '\001'
            return isTagChecked(I.I(1528));

        case 2: // '\002'
            return isTagChecked(I.I(1556));

        case 4: // '\004'
            return isTagChecked(I.I(1589));

        case 3: // '\003'
        default:
            return false;
        }
    }

    public final String getParseIdentityTag()
    {
        return I.I(6973);
    }
}
